#include <iostream>

class csum
{
	public:
	int add(int a, int b) 	/* 实际上原型 add(this, int a, int b) */
	{
		return (a + b);
	}
};

int main()
{
	csum sum;
	sum.add(1, 2);

	return 0;
}

#if 0

int main()
{
    1189:	f3 0f 1e fa          	endbr64 
    118d:	55                   	push   %rbp
    118e:	48 89 e5             	mov    %rsp,%rbp			# rbp = rsp
    1191:	48 83 ec 10          	sub    $0x10,%rsp			# 申请两个8字节栈空间
    1195:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax		# 把fs的偏移值x28放入rax
																# 指向特定于线程或定义的结构
																# %fs:0x28主要是用来起sentinel(哨兵)的作用
    119c:	00 00 
    119e:	48 89 45 f8          	mov    %rax,-0x8(%rbp)      # 防止overflow的，即使用了8字节进行安全保护
    11a2:	31 c0                	xor    %eax,%eax			# eax 清零
	csum sum;
	sum.add(1, 2);
    11a4:	48 8d 45 f7          	lea    -0x9(%rbp),%rax		# rbp-0x9的地址放入rax，即this指针
    11a8:	ba 02 00 00 00       	mov    $0x2,%edx			# edx = 2
    11ad:	be 01 00 00 00       	mov    $0x1,%esi			# esi = 1
    11b2:	48 89 c7             	mov    %rax,%rdi			# rdi = rax = this
    11b5:	e8 82 00 00 00       	callq  123c <_ZN4csum3addEii>

	return 0;
    11ba:	b8 00 00 00 00       	mov    $0x0,%eax			# 返回值
}

000000000000123c <_ZN4csum3addEii>:
	int add(int a, int b) 	
    123c:	f3 0f 1e fa          	endbr64 
    1240:	55                   	push   %rbp
    1241:	48 89 e5             	mov    %rsp,%rbp
    1244:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)		# rbp-0x8 = rdi = this
    1248:	89 75 f4             	mov    %esi,-0xc(%rbp)		# rbp-0xc = esi = 1
    124b:	89 55 f0             	mov    %edx,-0x10(%rbp)		# rbp-0x10 = edx = 2
		return (a + b);
    124e:	8b 55 f4             	mov    -0xc(%rbp),%edx		# 1
    1251:	8b 45 f0             	mov    -0x10(%rbp),%eax		# 2
    1254:	01 d0                	add    %edx,%eax			# edx = 1 + 2
	}
    1256:	5d                   	pop    %rbp
    1257:	c3                   	retq   

#endif

#if 0

/*
 * intel
 */
0000000000001189 <main>:
    1189:	f3 0f 1e fa          	endbr64 
    118d:	55                   	push   %rbp
    118e:	48 89 e5             	mov    %rsp,%rbp
    1191:	48 83 ec 10          	sub    $0x10,%rsp
    1195:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax
    119c:	00 00 
    119e:	48 89 45 f8          	mov    %rax,-0x8(%rbp)
    11a2:	31 c0                	xor    %eax,%eax		// eax=0
    11a4:	48 8d 45 f7          	lea    -0x9(%rbp),%rax		// rax=(rbp-0x9)
    11a8:	ba 02 00 00 00       	mov    $0x2,%edx		// edx=0x2
    11ad:	be 01 00 00 00       	mov    $0x1,%esi		// esi=0x1
    11b2:	48 89 c7             	mov    %rax,%rdi		// rdi=rax
    11b5:	e8 82 00 00 00       	callq  123c <_ZN4csum3addEii>	// (rdi, esi, edx)
    11ba:	b8 00 00 00 00       	mov    $0x0,%eax		// eax=0
    11bf:	48 8b 4d f8          	mov    -0x8(%rbp),%rcx		// rcx=(rbp-0x8)
    11c3:	64 48 33 0c 25 28 00 	xor    %fs:0x28,%rcx
    11ca:	00 00 
    11cc:	74 05                	je     11d3 <main+0x4a>
    11ce:	e8 ad fe ff ff       	callq  1080 <__stack_chk_fail@plt>
    11d3:	c9                   	leaveq 
    11d4:	c3                   	retq   

00000000000011d5 <_Z41__static_initialization_and_destruction_0ii>:
    11d5:	f3 0f 1e fa          	endbr64 
    11d9:	55                   	push   %rbp
    11da:	48 89 e5             	mov    %rsp,%rbp
    11dd:	48 83 ec 10          	sub    $0x10,%rsp		// rsp-=0x10
    11e1:	89 7d fc             	mov    %edi,-0x4(%rbp)		// (rbp-0x4)=edi
    11e4:	89 75 f8             	mov    %esi,-0x8(%rbp)		// (rbp-0x8)=esi
    11e7:	83 7d fc 01          	cmpl   $0x1,-0x4(%rbp)		// (rbp-0x4)-0x1
    11eb:	75 32                	jne    121f <_Z41__static_initialization_and_destruction_0ii+0x4a>   不等/非零
    11ed:	81 7d f8 ff ff 00 00 	cmpl   $0xffff,-0x8(%rbp)	// (rbp-0x8)-0xffff
    11f4:	75 29                	jne    121f <_Z41__static_initialization_and_destruction_0ii+0x4a>   不等/非零
    11f6:	48 8d 3d 14 2e 00 00 	lea    0x2e14(%rip),%rdi        # 4011 <_ZStL8__ioinit>	rdi=rip+0x2e14
    11fd:	e8 8e fe ff ff       	callq  1090 <_ZNSt8ios_base4InitC1Ev@plt>
    1202:	48 8d 15 ff 2d 00 00 	lea    0x2dff(%rip),%rdx        # 4008 <__dso_handle>
    1209:	48 8d 35 01 2e 00 00 	lea    0x2e01(%rip),%rsi        # 4011 <_ZStL8__ioinit>
    1210:	48 8b 05 e1 2d 00 00 	mov    0x2de1(%rip),%rax        # 3ff8 <_ZNSt8ios_base4InitD1Ev@GLIBCXX_3.4>
    1217:	48 89 c7             	mov    %rax,%rdi
    121a:	e8 51 fe ff ff       	callq  1070 <__cxa_atexit@plt>
    121f:	90                   	nop
    1220:	c9                   	leaveq 
    1221:	c3                   	retq   

0000000000001222 <_GLOBAL__sub_I_main>:
    1222:	f3 0f 1e fa          	endbr64 
    1226:	55                   	push   %rbp
    1227:	48 89 e5             	mov    %rsp,%rbp
    122a:	be ff ff 00 00       	mov    $0xffff,%esi	// esi=0xffff
    122f:	bf 01 00 00 00       	mov    $0x1,%edi	// edi=0x1
    1234:	e8 9c ff ff ff       	callq  11d5 <_Z41__static_initialization_and_destruction_0ii>
    1239:	5d                   	pop    %rbp
    123a:	c3                   	retq   
    123b:	90                   	nop

000000000000123c <_ZN4csum3addEii>:
    123c:	f3 0f 1e fa          	endbr64 
    1240:	55                   	push   %rbp
    1241:	48 89 e5             	mov    %rsp,%rbp
    1244:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)	// (rbp-0x8)=rdi
    1248:	89 75 f4             	mov    %esi,-0xc(%rbp)	// (rbp-0xc)=esi
    124b:	89 55 f0             	mov    %edx,-0x10(%rbp)	// (rbp-0x10)=edx
    124e:	8b 55 f4             	mov    -0xc(%rbp),%edx	// edx=(rbp-0xc)
    1251:	8b 45 f0             	mov    -0x10(%rbp),%eax	// eax=(rbp-0x10)
    1254:	01 d0                	add    %edx,%eax	// eax+=edx
    1256:	5d                   	pop    %rbp
    1257:	c3                   	retq   
    1258:	0f 1f 84 00 00 00 00 	nopl   0x0(%rax,%rax,1)
    125f:	00 


/*
 * arm
 */
000000000040071c <main>:
  40071c:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400720:	910003fd 	mov	x29, sp
  400724:	910063a0 	add	x0, x29, #0x18		// x0=x29+0x18
  400728:	52800042 	mov	w2, #0x2                   	// #2
  40072c:	52800021 	mov	w1, #0x1                   	// #1
  400730:	94000023 	bl	4007bc <_ZN4csum3addEii>
  400734:	52800000 	mov	w0, #0x0                   	// #0
  400738:	a8c27bfd 	ldp	x29, x30, [sp], #32
  40073c:	d65f03c0 	ret

0000000000400740 <_Z41__static_initialization_and_destruction_0ii>:
  400740:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400744:	910003fd 	mov	x29, sp
  400748:	b9001fa0 	str	w0, [x29, #28]	// [x29+28]=w0
  40074c:	b9001ba1 	str	w1, [x29, #24]	// [x29+24]=w1
  400750:	b9401fa0 	ldr	w0, [x29, #28]	// w0=[x29+28]
  400754:	7100041f 	cmp	w0, #0x1	// w0-0x1
  400758:	540001e1 	b.ne	400794 <_Z41__static_initialization_and_destruction_0ii+0x54>  // b.any	不等/非零
  40075c:	b9401ba1 	ldr	w1, [x29, #24]	// w1=[x29+24]
  400760:	529fffe0 	mov	w0, #0xffff                	// #65535
  400764:	6b00003f 	cmp	w1, w0		// w1-w0
  400768:	54000161 	b.ne	400794 <_Z41__static_initialization_and_destruction_0ii+0x54>  // b.any
  40076c:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  400770:	91012000 	add	x0, x0, #0x48
  400774:	97ffff9b 	bl	4005e0 <_ZNSt8ios_base4InitC1Ev@plt>
  400778:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  40077c:	9100e002 	add	x2, x0, #0x38
  400780:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  400784:	91012001 	add	x1, x0, #0x48
  400788:	90000000 	adrp	x0, 400000 <_init-0x588>
  40078c:	91180000 	add	x0, x0, #0x600
  400790:	97ffff98 	bl	4005f0 <__cxa_atexit@plt>
  400794:	d503201f 	nop
  400798:	a8c27bfd 	ldp	x29, x30, [sp], #32
  40079c:	d65f03c0 	ret

00000000004007a0 <_GLOBAL__sub_I_main>:
  4007a0:	a9bf7bfd 	stp	x29, x30, [sp, #-16]!
  4007a4:	910003fd 	mov	x29, sp
  4007a8:	529fffe1 	mov	w1, #0xffff                	// #65535
  4007ac:	52800020 	mov	w0, #0x1                   	// #1
  4007b0:	97ffffe4 	bl	400740 <_Z41__static_initialization_and_destruction_0ii>
  4007b4:	a8c17bfd 	ldp	x29, x30, [sp], #16
  4007b8:	d65f03c0 	ret

00000000004007bc <_ZN4csum3addEii>:
  4007bc:	d10043ff 	sub	sp, sp, #0x10
  4007c0:	f90007e0 	str	x0, [sp, #8]	// [sp+8]=x0
  4007c4:	b90007e1 	str	w1, [sp, #4]	// [sp+4]=w1
  4007c8:	b90003e2 	str	w2, [sp]	// [sp]=w2
  4007cc:	b94007e1 	ldr	w1, [sp, #4]	// w1=[sp+4]
  4007d0:	b94003e0 	ldr	w0, [sp]	// w0=[sp]
  4007d4:	0b000020 	add	w0, w1, w0	// w0=w1+w0
  4007d8:	910043ff 	add	sp, sp, #0x10
  4007dc:	d65f03c0 	ret

#endif
